package com.itheima.service.impl;

import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 数据报表ServiceImpl
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;
	
    @Override
    public JobOption getEmpJobData() {
        // 1. 统计各个职位的员工人数
        List<Map<String,Object>> list = empMapper.countEmpJobData();

        // 2. 取出职位名称和员工人数封装成对应集合
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();

        // 3. 将封装好的数据进行返回
        return new JobOption(jobList, dataList);
    }

    /**
     * 统计各个性别的员工人数
     *
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 统计各个学历的学员人数
     *
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /**
     * 统计各个班级的学员人数
     *
     * @return
     */
    @Override
    public ClazzOption getStudentCountData() {
        // 1. 统计各个班级的学员人数
        List<Map<String,Object>> list = clazzMapper.getStudentCountData();

        // 2. 取出职位名称和员工人数封装成对应集合
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("name")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("value")).toList();

        // 3. 将封装好的数据进行返回
        return new ClazzOption(clazzList, dataList);
    }
}